         
    jQuery(function() {
        //table
			var serverData = {};
			    var serverTable;
			    jQuery(document).ready(function () {
			        serverTable = jQuery('#dataTable').DataTable({
			            "serverSide": true,
			            "ordering": false,
			            "ajax": {
			                "dataType": "json",
			                "type": "get",
			                "cache": false,
			                "url":window.rootPath+ '/ui/inventoryReduce/getpage',
			                "data": function (d) {
			                    return $.extend({}, d, serverData);
			                }
			            },
			            columns: [
			                {
			                	data: null,
			                	defaultContent: ""
			                },
			                {
			                    data: null,
			                    defaultContent: "",
			                    render: function (data, type, full, meta) {
			                        var operate =' <input type="checkbox" class="checkchild" />';
			                        return operate;

			                    }
			                },
			                {
			                    data: 'figureNum',
								render:function(data,type,full,meta){
									if(data == null || data == undefined || data == ""){
										return data;
									}else{
										return (data.length > 40) ? '<font title="'+data+'">'+data.substring(0,40)+'...'+'</font>' : data;
									}
									//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
								}
			                },
			                {
			                    data: 'name',
								render:function(data,type,full,meta){
									if(data == null || data == undefined || data == ""){
										return data;
									}else{
										return (data.length > 40) ? '<font title="'+data+'">'+data.substring(0,40)+'...'+'</font>' : data;
									}
									//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
								}
			                },
			                {
			                    data: 'material',
								render:function(data,type,full,meta){
									if(data == null || data == undefined || data == ""){
										return data;
									}else{
										return (data.length > 40) ? '<font title="'+data+'">'+data.substring(0,40)+'...'+'</font>' : data;
									}
									//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
								}
			                },
			                {
			                	data: 'number'
			                },
			                
			                {
			                	data:null,
			                	render : function(data,type, full,meta) {
			                		var start=data.startDate;
			                		var end=data.endDate;
		    						if (start) 
		    						{
		    							if(end)
		    							return moment(start).format("YYYY-MM-DD")+" 至 "+moment(end).format("YYYY-MM-DD");
		    						}
			                	}          	
			                },
			                {
			                	data: 'user.empLogin.name'
			                }
			                ],
			            "drawCallback": function (oSettings) {
			                var k = 0;
			                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
			                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
			                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
			                    k++;
			                }
			            }
			        });

			    });
			    //强制释放占库
			    jQuery(".releaseBtn").on('click',function(){
			    	var selects=getSelect("#dataTable",1);
			      	   var url=window.rootPath+"/ui/inventoryReduce/release";
			      	   releaseSelect(selects,url,serverTable)
			    });
			    var releaseSelect=function(selects,url,tableName){
			    	if(selects.length==0){
			    	       $.springLemonDialog({
			    	         content: '请选择强制释放的记录',// 确认文本
			    	         clickButton: function (sender, modal, index) {// 按钮事件处理
			    	             $(this).closeDialog(modal);
			    	         }
			    	       }); 
			    	   }
			    	else{
			    		   var ids=selects[0].id;
			    		   for(var i=1;i<selects.length;i++){
			    			   ids += ',' + selects[i].id;  
			    		   }
			    		   var role = jQuery("#role").val();
//			    		   if(role=="管理员"){}
			    		   
			    		   var flag=0;
			    		   var userId = jQuery("#userId").val();
			    		   for(var n=0;n<selects.length;n++){
			    			   if(userId!=selects[n].user.id){
			    				   flag=1;
			    				   break;
			    			   }
			    		   }
			    		   if(flag==0||role=="系统管理员"){
				    		   var api=url+"?ids="+ids;
				    		   $.springLemonDialog({
				    		         content: '确认强制释放'+selects.length+'条占库？',// 确认文本
				    		         clickButton: function (sender, modal, index) {// 按钮事件处理
				    		        	 if (index == 0) {
				    		        		 jQuery.ajax({
				    		        			    url:encodeURI(api),
				    		        	            cache:false,
				    		        	            type :"get",
				    		        	            dataType:"json",
				    		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
				    		        	            success:function(data){
				    		        	            	tableName.draw(false); 
				    		        	            }
				    		        	        });	
				    		        	 }
				    		             $(this).closeDialog(modal);
				    		         }
				    		       });  
				    	}
			    		   else{
			    			   $.springLemonDialog({
					    	         content: '只能释放自己的记录，请重新选择',// 确认文本
					    	         clickButton: function (sender, modal, index) {// 按钮事件处理
					    	             $(this).closeDialog(modal);
					    	         }
					    	       }); 
			    		   }
			    		   
			    		   
			    	   }
			    }
			    	
			    //查询
			    jQuery(".searchBtn").on('click',function(){
			    	serverData.key=jQuery("#keyword").val();
			    	serverTable.draw();
			    });
			    
			    //撤消
			    jQuery(".resetBtn").on('click',function(){
			    	jQuery("#keyword").val('');
			    	serverData.key='';
			    	serverTable.draw();
			    });
			///////泵列表中的全选
			    jQuery("#checkAll").click(function(){
			    	var check = $(this).prop("checked");
			        jQuery(".checkchild").prop("checked", check);
				});
			    
	 });